import 'package:json_annotation/json_annotation.dart';

import 'action_type.dart';

class ActionTypeConverter implements JsonConverter<ActionType, String> {
  const ActionTypeConverter();

  @override
  ActionType fromJson(String json) {
    switch (json) {
      case 'send':
        return ActionType.send;
      case 'receive':
        return ActionType.receive;
      default:
        throw ArgumentError('未知类型：$json');
    }
  }

  @override
  String toJson(ActionType object) {
    return object.toString().split('.').last;
  }
}
